package com.ruoyi.client.controller;

import com.ruoyi.client.pojo.vo.IndexCarouselVo;
import com.ruoyi.client.pojo.vo.IndexDataVo;
import com.ruoyi.client.pojo.vo.IndexProductVo;
import com.ruoyi.client.service.IIndexService;
import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author：HuaQP
 * @Date：2024/4/23
 */
@Anonymous  //接口允许匿名访问
@RestController
public class IndexController extends BaseController {
    @Resource
    private IIndexService indexService;

    @GetMapping("/index")
    public AjaxResult index() {
        IndexDataVo indexDataVo = new IndexDataVo();
        // 获取轮播数据
        List<IndexCarouselVo> carouselItems = indexService.listCarouselItems();
        // 获取推荐数据
        List<IndexProductVo> recommendedItems = indexService.listRecommendedItems();
        // 获取新品数据
        List<IndexProductVo> newArrialItems = indexService.listNewArrialItems();
        // 获取销售排行
        List<IndexProductVo> topSaleItems = indexService.listTopSaleItems();

        indexDataVo.setCarouselItems(carouselItems);
        indexDataVo.setRecommendedItems(recommendedItems);
        indexDataVo.setNewArrialItems(newArrialItems);
        indexDataVo.setTopSaleItems(topSaleItems);

        return AjaxResult.success(indexDataVo);
    }
}
